﻿using ARchGL.Platform.WindowsService.Application;
using System;
using System.ServiceProcess;
using System.Threading;

namespace ARchGL.Platform.WindowsService
{
    public partial class ProjectLEDService : ServiceBase
    {
        public ProjectLEDService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            var thread = new Thread(() =>
            {
                var led = new LEDService();
                while (true)
                {
                    try
                    {
                        //指定时间点执行一次清屏

                        var result = led.RequestContent();
                        //led.SendContent(content);
                        //led.SendContent("--------" + DateTime.Now.ToString("HH:mm:ss"));
                        if (result.Result.Switch == 1) led.SendBitmap(result);

                        Thread.Sleep(30000); //30秒请求一次
                    }
                    catch (Exception ex)
                    {
                        led.SendContent(ex.Message);
                    }
                }
            })
            { IsBackground = true };
            thread.Start();
        }

        protected override void OnStop()
        {
        }
    }
}
